package com.example.game;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.example.game.GamePage.player;

public class HelpPage extends AppCompatActivity implements View.OnClickListener{
    final List<Map<String, Object>> listitem = new ArrayList<Map<String, Object>>(); //存储数据的数组列表

    int[] image_expense = new int[]{R.drawable.tutior1, R.drawable.tutior2,R.drawable.tutior3}; //存储图片

    final int CONTENT_COUNT = image_expense.length;
    String[] content =new String[CONTENT_COUNT];
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.help_layout);
        final SimpleAdapter adapter = setUpAdapter();
        ListView listView = (ListView)findViewById(R.id.Help_ListView);
//        TextView textView = (TextView)findViewById(R.id.help_TextView);
//        textView.setText("");
        listView.setAdapter(adapter);
        Button bt = (Button)findViewById(R.id.About_Back_To_Main);
        bt.setOnClickListener(this);
    }



//    @Override
//    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//        Log.d("TAG_building_list", "onCreateView: building_page");
//        final View view = inflater.inflate(R.layout.building_fragment_layout, container, false);
//        final SimpleAdapter adapter = setUpAdapter();
//        final ListView listView = (ListView) view.findViewById(R.id.Building_ListView);
//        listView.setAdapter(adapter);
//    }

    @Override
    public void onClick(View v) {
        if(v.getId()==R.id.About_Back_To_Main)
        {
            finish();
            Intent intent = new Intent();
            intent.setClass(this,MainActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
        }
    }
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        //点击返回键调用方法
        if(keyCode== KeyEvent.KEYCODE_BACK){
            finish();
            Intent intent = new Intent();
            intent.setClass(this,MainActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
        }
        return false;
    }



    SimpleAdapter setUpAdapter(){
        String TAG = "TAG_setContent";

        put_adapter_content();



        //创建适配器
        // 第一个参数是上下文对象
        // 第二个是listitem
        // 第三个是指定每个列表项的布局文件
        // 第四个是指定Map对象中定义的两个键（这里通过字符串数组来指定）
        // 第五个是用于指定在布局文件中定义的id（也是用数组来指定）
        SimpleAdapter adapter = new SimpleAdapter(this
                , listitem
                , R.layout.help_item
                , new String[]{"image"}
                , new int[]{R.id.Help_ImageView});
        Log.d(TAG, "adapter settled");
        return adapter;
    }
    public void put_adapter_content(){
        listitem.clear();
        for(int i=0; i< CONTENT_COUNT; i++){
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("image", image_expense[i]);
            listitem.add(map);
        }
    }

}
